package meadproperty.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

import meadproperty.service.Config;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class XML2JavaUtil {
	
	public void java2XML(String xmlFile, Config cfg) throws Exception {
		
		XStream xs = new XStream();
		File file = new File(xmlFile);
		FileOutputStream fs = new FileOutputStream(file.getAbsoluteFile());
		Writer write = new OutputStreamWriter(fs);
		write.write("Hello, world\n");
		xs.toXML(cfg, fs);		
		System.out.println("ok3"+xmlFile);
	}

	public Config XML2Java(String xmlFile) throws FileNotFoundException {
		XStream reverse = new XStream(new DomDriver());
		Config cfg = new Config();
		FileInputStream fis = new FileInputStream(xmlFile);
		reverse.fromXML(fis, cfg);
		// fis.close();
		System.out.println(cfg.toString());
		return cfg;
	}
}
